package com.lbmb.mdps.workbench.controller;

import com.lbmb.mdps.commons.constant.Constant;
import com.lbmb.mdps.commons.domain.DeliverReceive;
import com.lbmb.mdps.commons.domain.InventoryReceive;
import com.lbmb.mdps.commons.domain.InventoryVo;
import com.lbmb.mdps.commons.domain.ReturnObjectVO;
import com.lbmb.mdps.commons.exception.InventoryException;
import com.lbmb.mdps.workbench.domain.Deliver;
import com.lbmb.mdps.workbench.service.InventoryService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 林文塨
 * @date 2022-05-30 23:11
 * description
 */
@CrossOrigin
@RestController
public class InventoryController {

    @Resource
    private InventoryService inventoryService;

    @PostMapping( "/workbench/inventory/inventoryPageList.do")
    public ReturnObjectVO inventoryPageList(@RequestBody InventoryReceive inventoryReceive) throws InventoryException {
        /*
         * 分页获取列表
         * @author 林文塨
         * @date 2022/5/30 23:15
         * @param [inventoryReceive]
         * @return com.lbmb.mdps.commons.domain.ReturnObjectVO
         */
        ReturnObjectVO rov = new ReturnObjectVO();

        inventoryReceive.setSkipCount((inventoryReceive.getPageNo()-1)*inventoryReceive.getPageSize());

        List<InventoryVo> inventoryVoList = inventoryService.inventoryPageList(inventoryReceive);

        rov.setOthers(inventoryVoList);
        rov.setCode(Constant.RETURN_OBJECT_CODE_SUCCESS);

        return rov;
    }

    @PostMapping( "/workbench/inventory/getInventoryTotal.do")
    public ReturnObjectVO getInventoryTotal(@RequestBody InventoryReceive inventoryReceive) throws InventoryException {
        /*
         * 获取分页总条数功能
         * @author 林文塨
         * @date 2022/5/30 10:38
         * @param [employeeReceive]
         * @return com.lbmb.mdps.commons.domain.ReturnObjectVO
         */
        ReturnObjectVO rov = new ReturnObjectVO();

        Integer total = inventoryService.getInventoryTotal(inventoryReceive);
        rov.setNumber(total);
        rov.setCode(Constant.RETURN_OBJECT_CODE_SUCCESS);

        return rov;
    }

    @PostMapping( "/workbench/inventory/deliver.do")
    public ReturnObjectVO deliver(@RequestBody DeliverReceive deliverReceive) throws InventoryException {
        /*
         * 出库功能
         * @author 林文塨
         * @date 2022/5/30 10:38
         * @param [employeeReceive]
         * @return com.lbmb.mdps.commons.domain.ReturnObjectVO
         */
        ReturnObjectVO rov = new ReturnObjectVO();

        inventoryService.deliver(deliverReceive);
        rov.setCode(Constant.RETURN_OBJECT_CODE_SUCCESS);

        return rov;
    }
}
